package com.yuejian_06.yuejian_06.activity;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.Toast;

import com.yuejian_06.yuejian_06.Listener.LoginListener;
import com.yuejian_06.yuejian_06.R;
import com.yuejian_06.yuejian_06.adapter.CourseAdapter;
import com.yuejian_06.yuejian_06.bean.CourseBean;
import com.yuejian_06.yuejian_06.model.CourseModel;

import java.util.List;

public class CourseSearchActivity extends BaseActivity {
    EditText name;
    ImageButton back;
    Button search_btn;
    RecyclerView recyclerView;

    private LoginListener<List<CourseBean>> Listener=new LoginListener<List<CourseBean>>() {
        @Override
        public void onResponse(List<CourseBean> o) {
            List<CourseBean> mDataList=o;
            recyclerView.setAdapter(new CourseAdapter(CourseSearchActivity.this,mDataList));//设置适配器
        }
        @Override
        public void onFail(String msg) {
            Toast.makeText(getApplicationContext(),"失败了",Toast.LENGTH_SHORT).show();

        }
    };
    @Override
    void initViews() {
        setLayout(R.layout.activity_course_search);
        name = (EditText)findViewById(R.id.courseS_name);
        back = (ImageButton)findViewById(R.id.courseS_back);
        search_btn = (Button)findViewById(R.id.courseS_btn);
        recyclerView = (RecyclerView)findViewById(R.id.course_rv);
        recyclerView.setLayoutManager(new LinearLayoutManager(CourseSearchActivity.this));// 布局

    }

    @Override    void initEvents() {
        search_btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                CourseModel courseModel=new CourseModel();
                courseModel.getcourseSearch(name.getText().toString(),Listener);
            }
        });

        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

    @Override
    void initData() {

    }

}
